using System;
using System.Collections.Generic;

namespace GatherTogether
{
    namespace GatherItems
    {
        /// <summary>
        /// This class represents a collections of locations for a specific gather type 
        /// (i.e. Copper Ore, Peacebloom, Solid Chest, etc.).
        /// </summary>
        class Node : IEnumerable<Location>, IComparable<Node>
        {
            protected GatherType m_nodeType = GatherType.Unknown;
            protected List<Location> m_nodeLocations = new List<Location>();
            protected string m_nodeTypeString = "";

            /// <summary>
            /// Default constructor.
            /// </summary>
            public Node()
            {
            }

            /// <summary>
            /// A constructor which takes the gather type ID number as an argument.
            /// </summary>
            /// <param name="nodeID"></param>
            public Node(ulong nodeID)
            {
                m_nodeType = (GatherType)nodeID;
                // TODO: Error checking. If nodeID is not one of the known types then
                // m_nodeType should be set to GatherType.unknown
            }

            public IEnumerator<Location> GetEnumerator()
            {
                foreach (Location location in m_nodeLocations)
                {
                    yield return location;
                }
            }

            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
            {
                return GetEnumerator();
            }

            public bool Equals(Node other)
            {
                return m_nodeType == other.m_nodeType;
            }

            public int CompareTo(Node other)
            {
                return m_nodeType.CompareTo(other.m_nodeType);
            }

            /// <summary>
            /// Accessor for the gatherable item type.
            /// </summary>
            public GatherType type
            {
                get { return m_nodeType; }
                set { m_nodeType = value; }
            }

            public string typeString
            {
                get { return m_nodeTypeString; }
                set { m_nodeTypeString = value; }
            }

            /// <summary>
            /// Adds a location to the list of locations for this node type.
            /// </summary>
            /// <param name="location"></param>
            public void Add(Location location)
            {
                m_nodeLocations.Add(location);
            }

            public void Merge(Node otherNode)
            {
                foreach (Location location in otherNode)
                    m_nodeLocations.Add(location);
            }

            public enum GatherType : ulong
            {
                Unknown = 0,
                // Veins
                SmallThorium = 324,
                Incendite = 1610,
                Copper = 1731,
                Tin = 1732,
                Silver = 1733,
                Gold = 1734,
                Iron = 1735,
                Mithril = 2040,
                Truesilver = 2047,
                LesserBloodstone = 2653,
                Indurium = 19903,
                OozeSilver = 73940,
                OozeGold = 73941,
                OozeTruesilver = 123309,
                OozeMithril = 123310,
                DarkIron = 165658,
                RichThorium = 175404,
                OozeRichThorium = 177388,
                HakkariThorium = 180215,
                FelIron = 181555,
                Adamantite = 181556,
                RichAdamantite = 181557,
                SmallObsidian = 181068,
                LargeObsidian = 181069,
                // Herbs
                Silverleaf = 1617,
                Peacebloom = 1618,
                Earthroot = 1619,
                Mageroyal = 1620,
                Briarthorn = 1621,
                Bruiseweed = 1622,
                WildSteelbloom = 1623,
                Kingsblood = 1624,
                GraveMoss = 1628,
                Liferoot = 2041,
                Fadeleaf = 2042,
                KhadgarsWhisker = 2043,
                Wintersbite = 2044,
                Stranglekelp = 2045,
                Goldthorn = 2046,
                Firebloom = 2866,
                PurpleLotus = 142140,
                ArthasTear = 142141,
                Sungrass = 142142,
                Blindweed = 142143,
                GhostMushroom = 142144,
                Gromsblood = 142145,
                GoldenSansam = 176583,
                Dreamfoil = 176584,
                MountainSilversage = 176586,
                Plaguebloom = 176587,
                Icecap = 176588,
                BlackLotus = 176589,
                Bloodthistle = 181166,
                Felweed = 181270,
                DreamingGlory = 181271,
                Ragveil = 181275,
                FlameCap = 181276,
                Terocone = 181277,
                AncientLichen = 181278,
                Netherbloom = 181279,
                NightmareVine = 181280,
                ManaThistle = 181281,
                // Treasure
                HiddenStrongbox = 2039,
                GiantClam = 2744,
                BatteredChest = 2843,
                TatteredChest = 2844,
                SolidChest = 2850,
                WaterBarrel = 3658,
                MelonJuiceBarrel = 3659,
                ArmorCrate = 3660,
                WeaponCrate = 3661,
                FoodCrate = 3662,
                MilkBarrel = 3705,
                SweetNectarBarrel = 3706,
                AllianceStrongbox = 3714,
                AssortedPartsBox = 19019,
                RustyChest = 19021,
                LargeIronBoundChest = 74447,
                LargeSolidChest = 74448,
                LargeBatteredChest = 75293,
                LargeMithrilBoundChest = 131978,
                LargeDarkwoodChest = 131979,
                HordeSupplyCrate = 142191,
                UngoroDirtPile = 157936,
                BluePowerCrystal = 164658,
                GreenPowerCrystal = 164659,
                RedPowerCrystal = 164660,
                YellowPowerCrystal = 164661,
                BloodpetalSprout = 164958,
                BloodOfHeroes = 176213,
                ShellfishTrap = 176582,
                PracticeLockbox = 178244,
                BatteredFootlocker = 179486,
                WaterloggedFootlocker = 179487,
                DentedFootlocker = 179492,
                MossyFootlocker = 179493,
                ScarletFootlocker = 179498,
                EmptyBarrel = 181628,
                Glowcap = 182053,
                SolidFelIronChest = 184930,
                BoundFelIronChest = 184931,
                BoundAdamantiteChest = 184936,
                SolidAdamantiteChest = 184939,
                CleansedNightDragon = 164881,
                CleansedSongflower = 164882,
                CleansedWhipperRoot = 164883,
                CleansedWindblossom = 164884
            }
        }
    }
}
